package com.android.parrillaradio;

import java.util.HashMap;
import java.util.LinkedList;

import android.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class Main extends Activity {
	static final String DATA_TITLE = "T";
	static final String DATA_LINK = "L";

	static LinkedList<HashMap<String, String>> data;

	private ProgressDialog progressDialog;

	private void setData(LinkedList<HashMap<String, String>> data) {

		SimpleAdapter sAdapter = new SimpleAdapter(getApplicationContext(),
				data, android.R.layout.two_line_list_item, new String[] {
						DATA_TITLE, DATA_LINK }, new int[] {
						android.R.id.text1, android.R.id.text2 });

		ListView lv = (ListView) findViewById(R.id.lstData);

		lv.setAdapter(sAdapter);

	}

	private final Handler progressHandler = new Handler() {

		@SuppressWarnings("unchecked")
		public void handleMessage(Message msg) {

			if (msg.obj != null) {

				data = (LinkedList<HashMap<String, String>>) msg.obj;

				setData(data);

			}
			progressDialog.dismiss();

		}

	};

	private void loadData() {
		ProgressDialog progressDialog = ProgressDialog.show(Main.this, "",
				"Por favor espere mientras se cargan los datos...", true);
		new Thread(new Runnable() {
			@Override
			public void run() {
				XMLParser parser = new XMLParser(feedUrl);
				Message msg = progressHandler.obtainMessage();
				msg.obj = parser.parse();
				progressHandler.sendMessage(msg);
			}
		}).start();
	}
	
	Button btn = (Button) findViewById(R.id.btnLoad);

	btn.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v) {
			}
		});
}
